<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.xxfset.js"></script>
<script type="text/javascript">
$.fn.extend({
	xxfile:function(obj){
		var that=this;
		var eid=that[0].id;
		var _obj={
			url:"admin_defaultUp.php",
			accept:"",
			data:{},
			maxsize:2*1024*1024,//Byte
			multiple:false,
			success:function(data){
						var _k=this.k;
						document.getElementById(eid+"_prostatus_"+_k).innerHTML=(data==1?"处理成功":"<span style='color:red;'>异常！["+data+"]</span>");
						setTimeout(function(){
							$("#"+eid+"_progressbar_"+_k).hide(2000);
						},data==1?3000:10000);
					},
			error:function(data){
						alert(data);
					}
		};
		$.extend(_obj,obj);
		this[0].accept=_obj.accept||this[0].accept;
		this[0].multiple=_obj.multiple||this[0].multiple;
		this.change(function(){
			$.each(this.files,function(k,v){
				this.pid=k;
				var fthat=this;
				that.after("<div id='"+eid+"_progressbar_"+k+"' style='padding:2px;margin:3px;border:1px solid #99d9ea;'><div style='font-size:8px;'>"+v.name+" <span id='"+eid+"_prostatus_"+k+"'>上传中。。。</span></div><progress id='"+eid+"_progress_"+k+"' max='100' value='0' style='width:100%;height:5px;'></progress></div>");
				if(v.size<=_obj.maxsize){
					var formdata=new FormData();
					formdata.append("file",v);
					formdata.append("progressbarID",k);
					for(e in _obj.data){
						formdata.append(e,_obj.data[e]);
					}
					$.ajax({
						url:_obj.url,  
						type: 'POST',  
						data: formdata, 
						cache: false,
						context:{k:k},
						contentType: false,  
						processData: false,  
						success:_obj.success,
						error:_obj.error,
						xhr:function() {
							myXhr = $.ajaxSettings.xhr();
							if(myXhr.upload){
								myXhr.upload.addEventListener('progress',function(event){
									if(event.lengthComputable){
										var complete=(event.loaded/event.total*100|0);
										document.getElementById(eid+"_progress_"+k).innerHTML=complete;
										document.getElementById(eid+"_progress_"+k).value=complete;
										console.log(v.name+complete);
										if(complete==100){
											document.getElementById(eid+"_prostatus_"+k).innerHTML="稍等。。。";
										}
									}
								}, false);
							}
							return myXhr;
						}
					});
				}else{
					document.getElementById(eid+"_prostatus_"+k).innerHTML="<span style='color:red;'>异常！[文件过大]</span>";
					setTimeout(function(){
						$("#"+eid+"_progressbar_"+k).hide(2000);
					},10000);
				}
			});
		});
	}
});
</script>
<input id="uppic" type="file" accept="" multiple/>
<progress value="45" max="100">40</progress>
<button>123</button>
<script>
function a(str,fn){
	console.log(!(typeof fn == 'undefined'));
}
a(2);
	$("#uppic").xxfile({
		url:"test",
		maxsize:10*1024*1024,
		data:{
			type:"upload"
		}
	});
</script>